<template>
  <div>
    <div class="qup-page-heade bread-box">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item class="btn-green" @click.native="goBack(false)">非公司品牌处理</el-breadcrumb-item>
        <el-breadcrumb-item>{{ breadcrumbTitle }}</el-breadcrumb-item>
      </el-breadcrumb>
      <div>
        <el-button size="mini" @click.native="goBack(false)">返回</el-button>
      </div>
    </div>
    <div v-loading="loading">

      <ConsComp title="门店基础信息">
        <template v-slot:content>
          <el-form
            ref="baseShopForm"
            style="margin-top:20px"
            :model="baseShopDTO"
            :rules="rules"
            size="mini"
            label-width="150px"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="门店编码:" prop="shopItem">
                  <input-with-dialog
                    ref="cliDialog"
                    v-model="baseShopDTO.shopItem"
                    :disabled="flag !=='new'"
                    :props="{label:'code',value:'code'}"
                    :config="shopInfoConfig"
                    @change="shopInfoChoose"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="门店名称:" prop="shopName">
                  {{ baseShopDTO.shopName }}
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="门店业务类型:" prop="shopBusinessType">
                  {{ matchDict(baseShopDTO.shopBusinessType, 'BIZ_TYPE') }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="门店经营面积:" prop="shopArea">
                  {{ baseShopDTO.shopArea }}
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="门店详细地址:" prop="shopAddress">
                  {{ baseShopDTO.shopAddress }}
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="客户经理:" prop="customerManagerName">
                  <Submitter
                    :default-val="baseShopDTO.customerManagerName"
                    :disabled="flag !=='new'"
                    @choose="customerChoose"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="所属客户名称:" prop="customerName">
                  {{ baseShopDTO.customerName }}
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="客户经营总面积:" prop="customerTotalArea">
                  {{ baseShopDTO.customerTotalArea }}
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属办事处:" prop="agencyName">
                  {{ baseShopDTO.agencyName }}
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </ConsComp>
      <ConsComp title="非公司品牌检查结果">
        <template v-slot:content>
          <el-form
            ref="nonCompanyBrandInsResForm"
            style="margin-top:20px"
            :model="nonCompanyBrandInspectionResultDTO"
            :rules="rules"
            size="mini"
            label-width="150px"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="检查日期:" prop="inspectionDate">
                  <el-date-picker
                    v-model="nonCompanyBrandInspectionResultDTO.inspectionDate"
                    :disabled="readonly"
                    style="width: 100%"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="提报人:" prop="submissionPeopleName">
                  <Submitter
                    :disabled="flag!=='new'"
                    flag="0"
                    :default-val="nonCompanyBrandInspectionResultDTO.submissionPeopleName"
                    @choose="submissionChoose"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="启用状态:" prop="enable">
                  {{ nonCompanyBrandInspectionResultDTO.enable===1?'启用':'禁用' }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="flag!=='new'?16:8">
                <el-form-item label="检查结果附件:" prop="inspectionResultAttachment">
                  <p class="file-p">
                    <fileUploader
                      ref="myUploader"
                      :data="inspectionResultAttachment"
                      :limit="1"
                      :show-download-temp="false"
                      :show-edit="false"
                      :show-remove="!readonly"
                      :show-upload="!readonly"
                      @remove="removeFileAttachment"
                      @upload-success="uploadSuccessFileAttachment"
                    />
                  </p>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="整改要求:" prop="rectificationRequirement">
                  <el-select
                    v-model="nonCompanyBrandInspectionResultDTO.rectificationRequirement"
                    :disabled="readonly"
                    style="width:100%"
                  >
                    <el-option
                      v-for="item in dictMap.RECTIFY_REQUIER"
                      :key="item.id"
                      :label="item.dictName"
                      :value="item.dictCode"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </ConsComp>
      <ConsComp title="非公司品牌整改跟进">
        <template v-slot:content>
          <el-form
            ref="nonCompanyBrandInsFoForm"
            style="margin-top:20px"
            :model="nonCompanyBrandRectificationFollowUpDTO"
            :rules="rules"
            size="mini"
            label-width="150px"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="有无非公司产品:" prop="isNonCompanyProduct">
                  <el-select v-model="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyProduct" :disabled="readonly">
                    <el-option label="有" :value="1" />
                    <el-option label="无" :value="0" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyProduct===1"
                :span="8"
              >
                <el-form-item
                  label="非公司产品主要品牌:"
                  prop="nonCompanyAreaMajorBrand"
                >
                  <el-input
                    v-model="nonCompanyBrandRectificationFollowUpDTO.nonCompanyAreaMajorBrand"
                    :disabled="readonly"
                  />
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyProduct===1"
                :span="8"
              >
                <el-form-item
                  label="非公司产品数量:"
                  prop="nonCompanyProductNumber"
                >
                  <el-input
                    v-model.number="nonCompanyBrandRectificationFollowUpDTO.nonCompanyProductNumber"
                    :disabled="readonly"
                  />
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyProduct===1"
                :span="24"
              >
                <el-form-item
                  label="非公司产品判断依据:"
                  prop="nonCompanyProductAccording"
                >
                  <el-input v-model="nonCompanyBrandRectificationFollowUpDTO.nonCompanyProductAccording" :disabled="readonly" type="textarea" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="有无非公司区域:" prop="isNonCompanyArea">
                  <el-select
                    v-model="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyArea"
                    :disabled="readonly"
                  >
                    <el-option label="有" :value="1" />
                    <el-option label="无" :value="0" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyArea===1"
                :span="8"
              >
                <el-form-item
                  label="非公司区域主要品牌:"
                  prop="nonCompanyProductMajorBrand"
                >
                  <el-input v-model="nonCompanyBrandRectificationFollowUpDTO.nonCompanyProductMajorBrand" :disabled="readonly" />
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyArea===1"
                :span="8"
              >
                <el-form-item
                  label="非公司区域面积:"
                  prop="nonCompanyArea"
                >
                  <el-input
                    v-model="nonCompanyBrandRectificationFollowUpDTO.nonCompanyArea"
                    :disabled="readonly"
                    @change="outherAreaChange"
                  />
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyArea===1"
                :span="8"
              >
                <el-form-item
                  label="非公司区域面积占比:"
                  prop="nonCompanyAreaRatio"
                >
                  {{ nonCompanyBrandRectificationFollowUpDTO.nonCompanyAreaRatio+' %'||'' }}
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isNonCompanyArea===1"
                :span="24"
              >
                <el-form-item
                  label="非公司区域判断依据:"
                  prop="nonCompanyAreaAccording"
                >
                  <el-input v-model="nonCompanyBrandRectificationFollowUpDTO.nonCompanyAreaAccording" type="textarea" :disabled="readonly" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="是否下发办事处:" prop="isIssueAgency">
                  <el-select v-model="nonCompanyBrandRectificationFollowUpDTO.isIssueAgency" :disabled="readonly">
                    <el-option label="否" :value="0" />
                    <el-option label="是" :value="1" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  v-if="nonCompanyBrandRectificationFollowUpDTO.isIssueAgency===1"
                  label="下发办事处日期:"
                  prop="issueAgencyTime"
                  :required="nonCompanyBrandRectificationFollowUpDTO.isIssueAgency===1"
                >
                  <el-date-picker
                    v-model="nonCompanyBrandRectificationFollowUpDTO.issueAgencyTime"
                    :disabled="readonly"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="沟通进度:" prop="communicationProgress">
                  <el-input
                    v-model="nonCompanyBrandRectificationFollowUpDTO.communicationProgress"
                    type="textarea"
                    :disabled="readonly"
                    maxlength="1500"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否完成整改:" prop="isCompleteRectification">
                  <el-select v-model="nonCompanyBrandRectificationFollowUpDTO.isCompleteRectification" :disabled="readonly" placeholder="">
                    <el-option label="是" :value="1" />
                    <el-option label="否" :value="0" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  v-if="nonCompanyBrandRectificationFollowUpDTO.isCompleteRectification	===1"
                  label="整改完成时间:"
                  prop="completeRecificationTime"
                  :required="nonCompanyBrandRectificationFollowUpDTO.isCompleteRectification===1"
                >
                  <el-date-picker
                    v-model="nonCompanyBrandRectificationFollowUpDTO.completeRecificationTime	"
                    type="date"
                    :disabled="readonly"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  v-if="nonCompanyBrandRectificationFollowUpDTO.isCompleteRectification===1"
                  label="整改结果:"
                  prop="rectificationResult"
                  :required="nonCompanyBrandRectificationFollowUpDTO.isCompleteRectification===1"
                >
                  <el-select
                    v-model="nonCompanyBrandRectificationFollowUpDTO.rectificationResult"
                    :disabled="readonly"
                  >
                    <el-option
                      v-for="item in dictMap.RECTIFY_TYPE"
                      :key="item.id"
                      :label="item.dictName"
                      :value="item.dictCode"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="0">
              <el-col :span="8">
                <el-form-item label="是否完成资料回传:" prop="isDataSentBack">
                  <el-select
                    v-model="nonCompanyBrandRectificationFollowUpDTO.isDataSentBack"
                    :disabled="readonly"
                    placeholder=""
                  >
                    <el-option label="是" :value="1" />
                    <el-option label="否" :value="0" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col
                v-if="nonCompanyBrandRectificationFollowUpDTO.isDataSentBack === 1"
                :span="24"
              >
                <el-form-item label="整改见证材料:" prop="rectificationWitnessMaterial">
                  <p class="file-p">
                    <fileUploader
                      ref="myUploader1"
                      :data="rectificationWitnessMaterial"
                      :limit="1"
                      :show-download-temp="false"
                      :show-edit="false"
                      :show-remove="!readonly"
                      :show-upload="!readonly"
                      @remove="removeFile"
                      @upload-success="uploadSuccessFile"
                    />
                  </p>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注:" prop="remark">
                  <el-input v-model="nonCompanyBrandRectificationFollowUpDTO.remark" :disabled="readonly" type="textarea" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="flag !=='view'" :gutter="0">
              <el-col :span="24" style="text-align:center;">
                <el-button type="default" @click="goBack">取消</el-button>
                <el-button type="primary" @click="confirm">确认</el-button>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </ConsComp>

    </div>
    <el-image-viewer
      v-if="showViewer"
      :on-close="closeViewer"
      :url-list="urlList"
    />

  </div>
</template>
<script>
import { getDictByPatchType } from '@/api/dataDict'
import ConsComp from '../../components/consComp'
import BackPageMixin from '@/mixins/backPage'
import FileUploader from '@/components/importFile/FileUploader'
import { outherAdd, outherBrandgetById, outherBrandEdit } from '@/api/rewardsPunishment'

import { searchCustomer } from '@/api/common.js'
export default {
  name: 'DetailChannelTask',
  components: {
    Submitter: () => import('../../components/SubmitterDialog'),
    ConsComp,
    FileUploader
  },
  mixins: [BackPageMixin],
  props: {
    flag: {
      type: String,
      default() {
        return 'new'
      }
    },
    row: {
      type: [Object, Array],
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false,
      importVisible: false,

      showViewer: false,
      urlList: [],
      fileTypeList: [],
      staffConfig: {
        title: '人员',
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/signingRealEstate/getPerson`,
        setting: [
          {
            prop: 'adAccount',
            title: '账号'
          },
          {
            prop: 'name',
            title: '名称'
          },
          {
            prop: 'tel',
            title: '电话'
          }
        ]
      },
      rules: {
        shopItem: [
          { required: true, message: '请选择门店编码', trigger: 'change' }
        ],
        customerManagerName: [
          { required: true, message: '请选择客户经理', trigger: 'change' }
        ],
        inspectionDate: [
          { required: true, message: '请选择检查日期', trigger: 'change' }
        ],
        submissionPeopleName: [
          { required: true, message: '请选择提报人', trigger: 'change' }
        ],
        rectificationRequirement: [
          { required: true, message: '请选择整改要求', trigger: 'change' }
        ],
        isNonCompanyProduct: [
          { required: true, message: '请选择有无非公司产品', trigger: 'change' }
        ],
        isNonCompanyArea: [
          { required: true, message: '请选择有无非公司区域', trigger: 'change' }
        ],
        nonCompanyAreaMajorBrand: [
          { required: true, message: '请输入非公司主要品牌', trigger: 'blur' }
        ],
        nonCompanyProductNumber: [
          { required: true, message: '请输入非公司主要品牌数量', trigger: 'blur', type: 'number' }
        ],
        nonCompanyProductAccording: [
          { required: true, message: '请输入非公司产品判断依据', trigger: 'blur' }
        ],
        nonCompanyProductMajorBrand: [
          { required: true, message: '请输入非公司区域主要品牌', trigger: 'blur' }
        ],
        nonCompanyArea: [
          { required: true, message: '请输入非公司区域面积', trigger: 'blur' },
          { validator(rule, value, callback, source, options) {
            if (value === null || value === '') return
            const reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
            // let reg = /^[1-9][0-9]*$/
            if (reg.test(value) && value >= 1) {
              return true
            }
            callback(new Error('请输入正确的面积'))
          }
          }
        ],
        nonCompanyAreaAccording: [
          { required: true, message: '请输入非公司区域判断依据', trigger: 'blur' }
        ],
        isIssueAgency: [
          { required: true, message: '请选择是否下发办事处', trigger: 'change' }
        ],
        issueAgencyTime: [
          { required: true, message: '请选择下发办事处日期', trigger: 'change' }
        ],
        isCompleteRectification: [
          { required: true, message: '请选择是否完成整改', trigger: 'change' }
        ],
        completeRecificationTime: [
          { required: true, message: '请选择完成整改日期', trigger: 'change' }
        ],
        rectificationResult: [
          { required: true, message: '请选择整改结果', trigger: 'change' }
        ],
        isDataSentBack: [
          { required: true, message: '请选择是否完成资料回传', trigger: 'change' }
        ],
        rectificationWitnessMaterial: [
          { required: true, message: '请上传整改见证材料', trigger: 'change' }
        ]
      },
      baseShopDTO: { },
      nonCompanyBrandInspectionResultDTO: {
        enable: 1,
        inspectionResultAttachment: ''
      },
      nonCompanyBrandRectificationFollowUpDTO: {
        rectificationWitnessMaterial: ''
      },
      shopInfoConfig: {
        title: '客户',
        interfacePath: `/select-service/api/v1/shop/page`,
        setting: [
          {
            prop: 'code',
            title: '编码'
          },
          {
            prop: 'name',
            title: '名称'
          }
        ]
      },
      customerConfig: {
        title: '客户经理',
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/signingRealEstate/getPerson`,
        setting: [
          {
            prop: 'code',
            title: '编码'
          },
          {
            prop: 'name',
            title: '名称'
          },
          {
            prop: 'tel',
            title: '电话'
          }
        ]
      },
      dictMap: {},
      inspectionResultAttachment: [],
      rectificationWitnessMaterial: [],
      consumerList: []
    }
  },
  computed: {
    readonly() {
      return this.flag === 'view'
    },
    breadcrumbTitle() {
      let title = ''
      switch (this.flag) {
        case 'view':
          title = '详情'
          break
        case 'new':
          title = '新增'
          break
        case 'edit':
          title = '编辑'
          break
        default:
          break
      }
      return title
    }
  },
  watch: { },
  async created() {
    await this.getDictByPatchTypeAll()
    if (this.flag !== 'new') {
      this.loading = true
      const { data } = await outherBrandgetById(this.row.id)
      this.patchDetail(data)
      this.loading = false
    }
  },
  methods: {
    fileView(filePath) {
      this.urlList = []
      const typeName = filePath.split('.')[1]
      if (typeName === 'jpg' || typeName === 'jpeg' || typeName === 'png') {
      // 图片预览
        this.showViewer = true
        const picUrl = process.env.VUE_APP_IMG_PREFIX + '/' + filePath
        this.urlList.push(picUrl)
      } else if (typeName === 'pdf' || typeName === 'doc' || typeName === 'docx' || typeName === 'xlsx' || typeName === 'xls') {
        // word,excel预览
        window.open(`${process.env.VUE_APP_OFFICE_PREFIX}?src=` + process.env.VUE_APP_IMG_PREFIX + typeName)
      } else {
        this.$message.warning('该文件类型不支持预览')
      }
    },
    // 关闭查看器
    closeViewer() {
      this.showViewer = false
      this.urlList = []
    },
    submissionChoose(data) {
      this.$set(this.nonCompanyBrandInspectionResultDTO, 'submissionPeopleName', data.name)
      this.$set(this.nonCompanyBrandInspectionResultDTO, 'submissionPeopleCode', data.staffCode)
    },
    removeFileAttachment(data) {
      this.inspectionResultAttachment = []
      this.nonCompanyBrandInspectionResultDTO.inspectionResultAttachment = ''
      this.$refs.myUploader.clearUploadFile()
    },
    removeFile(data) {
      this.rectificationWitnessMaterial = []
      this.nonCompanyBrandRectificationFollowUpDTO.rectificationWitnessMaterial = ''
      this.$refs.myUploader1.clearUploadFile()
    },
    uploadSuccessFileAttachment(data) {
      this.inspectionResultAttachment = [...data.list]
      this.nonCompanyBrandInspectionResultDTO.inspectionResultAttachment = data.list[0].attachmentUrl || ''
    },
    uploadSuccessFile(data) {
      this.rectificationWitnessMaterial = [...data.list]
      this.nonCompanyBrandRectificationFollowUpDTO.rectificationWitnessMaterial = data.list[0].attachmentUrl || ''
    },
    matchFileName(path) {
      if (!path) return ''
      const pathArr = path.split('/')
      return pathArr[pathArr.length - 1]
    },
    patchDetail(data) {
      for (const key in data) {
        const ele = data[key]
        this.$set(this, key, ele)
      }
      this.baseShopDTO.shopItem = [{
        name: this.baseShopDTO.shopName,
        code: this.baseShopDTO.shopCode,
        shopAddr: this.baseShopDTO.shopAddress,
        businessType: this.baseShopDTO.shopBusinessType,
        operateArea: this.baseShopDTO.shopArea
      }]
      if (this.nonCompanyBrandInspectionResultDTO.inspectionResultAttachment) {
        this.inspectionResultAttachment = [{
          attachmentName: this.matchFileName(this.nonCompanyBrandInspectionResultDTO.inspectionResultAttachment),
          attachmentUrl: this.nonCompanyBrandInspectionResultDTO.inspectionResultAttachment,
          dr: 0
        }]
      }
      if (this.nonCompanyBrandRectificationFollowUpDTO.rectificationWitnessMaterial) {
        this.rectificationWitnessMaterial = [{
          attachmentName: this.matchFileName(this.nonCompanyBrandRectificationFollowUpDTO.rectificationWitnessMaterial),
          attachmentUrl: this.nonCompanyBrandRectificationFollowUpDTO.rectificationWitnessMaterial,
          dr: 0
        }]
      }
    },
    matchDict(val, type) {
      if (val == null || val === 'undefined') return ''
      const list = this.dictMap[type]
      const valArr = (val).toString().split(',')
      if (valArr.length > 1) {
        let str = ''
        for (let i = 0; i < valArr.length; i++) {
          const ele = valArr[i]
          const filterItem = list.filter(item => item.dictCode === ele)
          str += (filterItem[0] && filterItem[0].dictName || '') + ','
        }
        return str.substring(0, str.length - 1)
      }
      const filterItem = list.filter(item => item.dictCode === val)
      return filterItem[0] && filterItem[0].dictName || ''
    },
    async getDictByPatchTypeAll() {
      const dictRes = await getDictByPatchType(['RECTIFY_TYPE', 'BIZ_TYPE', 'RECTIFY_REQUIER'])
      this.$set(this, 'dictMap', dictRes)
    },
    outherAreaChange(v) {
      const areaRatio = (v / this.baseShopDTO.shopArea) * 100
      this.$set(this.nonCompanyBrandRectificationFollowUpDTO, 'nonCompanyAreaRatio', areaRatio.toFixed(2))
    },
    customerChoose(row) {
      this.$set(this.baseShopDTO, 'customerManagerName', row.name)
      this.$set(this.baseShopDTO, 'customerManagerCode', row.code)
    },
    async shopInfoChoose(row) {
      const info = row[0]
      for (const key in info) {
        const ele = info[key]
        this.$set(this.baseShopDTO, key, ele)
      }
      this.baseShopDTO.shopName = info.name
      this.baseShopDTO.shopCode = info.code
      this.baseShopDTO.shopAddress = info.shopAddr
      this.baseShopDTO.shopBusinessType = info.businessType
      this.baseShopDTO.shopArea = info.operateArea
      this.baseShopDTO.marketLevel = info.cityLevel
      await searchCustomer(info.customerCode, 'otherbrand').then(res => {
        if (res.success && res.data.records.length > 0) {
          const { operateArea } = res.data.records[0]
          this.$set(this.baseShopDTO, 'customerTotalArea', operateArea)
        }
      })
    },
    checkForm(formName) {
      const fn = Array.isArray(formName) ? formName : [formName]
      const res = []
      fn.map(item => {
        this.$refs[item].validate((valid) => {
          if (valid) {
            res.push(true)
          } else {
            res.push(false)
          }
        })
      })
      return res.every(item => item === true)
    },
    goBack(flag) {
      this.$emit('close', flag)
    },
    async confirm() {
      const checkRes = await this.checkForm(['baseShopForm', 'nonCompanyBrandInsResForm', 'nonCompanyBrandInsFoForm']) // 门店基础信息
      if (!checkRes) return
      this.loading = true
      try {
        delete this.baseShopDTO['id']
        const params = {
          baseShopDTO: this.baseShopDTO,
          nonCompanyBrandInspectionResultDTO: this.nonCompanyBrandInspectionResultDTO,
          nonCompanyBrandRectificationFollowUpDTO: this.nonCompanyBrandRectificationFollowUpDTO
        }
        if (this.flag === 'new') {
          const res = await outherAdd(params)
          if (res.success === 1) {
            this.$message.success('新增成功')
            const timer = setTimeout(() => {
              this.goBack(true)
              window.clearTimeout(timer)
            }, 800)
          } else {
            this.$message.warning(res.msg)
          }
        } else {
          const res = await outherBrandEdit(params)
          if (res.success === 1) {
            this.$message.success('编辑成功')
            const timer = setTimeout(() => {
              this.goBack(true)
              window.clearTimeout(timer)
            }, 800)
          } else {
            this.$message.warning(res.msg)
          }
        }
        this.loading = false
      } catch (error) {
        this.loading = false
      }
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/ .el-breadcrumb__inner{
    color: $qup-color-primary;
  }
.el-select, .el-date-editor.el-input{
  width:100%;
}
/deep/.file-p {
  margin:0;
  padding:0;
  .container{
    min-height:auto;
    height:auto;
  }
}
/deep/ .el-upload-list__item:first-child{
  margin-top:0;
}
 /deep/.el-autocomplete{
    width:100%;
  }
   /deep/.el-date-editor.el-input{
    width:100%;
  }
</style>
